﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;

namespace BenzInfo.Hockey.LHRAF.Models
{
    public class LHRAFInitializer : IDatabaseInitializer<LHRAFContext>
    {
        public void InitializeDatabase(LHRAFContext context)
        {
            if (System.Diagnostics.Debugger.IsAttached && context.Database.Exists()) // && !context.Database.CompatibleWithModel(false)
            {
                context.Database.Delete();
            }

            //string sqlscript = (context as IObjectContextAdapter).ObjectContext.CreateDatabaseScript();

            //context.Database.ExecuteSqlCommand(sqlscript, new object[] { });

            if (!context.Database.Exists())
            {
                context.Database.Create();
                context.Users.Add(new User()
                {
                    FirstName = "Benoit",
                    LastName = "Lapointe",
                    UserName = "b",
                    Password = "l",
                    Position = 1,
                    Category = User.CategoryEnum.Administrator
                });

                context.SaveChanges();
            }
        }
    }
}